import React, { useEffect, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import { Badge, Descriptions, Card, Button } from 'antd'
import { reqHospitalShow } from '@api/hospital/hospitalList'
import { IhospitalShow } from '@api/hospital/hospitalList/model/hospitalListTypes'

export default function HospitalListShow() {
  // 将属性state重命名为id
  const { state: id } = useLocation()

  const navigate = useNavigate()

  // 医院详情的状态
  const [hospital, setHospital] = useState<IhospitalShow>({})
  useEffect(() => {
    async function fetch() {
      const result = await reqHospitalShow(id as string)
      setHospital(result)
    }
    fetch()
  }, [])

  return (
    <Card>
      {/* column 控制一行有几个Item. 默认值是3 */}
      <Descriptions title="基本信息" bordered column={2}>
        <Descriptions.Item label="医院名称">
          {/* 在获取对象属性的后面加? 是es中新提出的一个技术,叫做可选链. 如果?前面不是undefined则会继续获取后面属性的值,如果是undefined后面的属性就不执行了 */}
          {hospital.hospital?.hosname}
        </Descriptions.Item>
        <Descriptions.Item label="医院logo">
          <img
            src={' data:image/png;base64,' + hospital.hospital?.logoData}
            alt=""
            width={80}
          />
        </Descriptions.Item>
        <Descriptions.Item label="医院编码">
          {hospital.hospital?.hoscode}
        </Descriptions.Item>
        <Descriptions.Item label="医院地址">
          {hospital.hospital?.param.fullAddress}
        </Descriptions.Item>
        {/* span={2} 表示当前的一个Item.占用一行中两个Item的位置 */}
        <Descriptions.Item label="坐车路线" span={2}>
          {hospital.hospital?.route}
        </Descriptions.Item>
        <Descriptions.Item label="医院简介" span={2}>
          {hospital.hospital?.intro}
        </Descriptions.Item>
      </Descriptions>
      <Descriptions
        title="预约规则信息"
        bordered
        column={2}
        style={{ marginTop: 20, marginBottom: 20 }}
      >
        <Descriptions.Item label="预约周期">
          {hospital.bookingRule?.cycle + '天'}
        </Descriptions.Item>
        <Descriptions.Item label="放号时间">
          {hospital.bookingRule?.releaseTime}
        </Descriptions.Item>
        <Descriptions.Item label="停挂时间">
          {hospital.bookingRule?.stopTime}
        </Descriptions.Item>
        <Descriptions.Item label="退号时间">
          {hospital.bookingRule?.quitTime}
        </Descriptions.Item>
        {/* span={2} 表示当前的一个Item.占用一行中两个Item的位置 */}
        <Descriptions.Item label="预约规则" span={2}>
          {hospital.bookingRule?.rule.map((item, index) => {
            return (
              <div key={index}>
                {index + 1}.{item}
              </div>
            )
          })}
        </Descriptions.Item>
      </Descriptions>

      <Button
        onClick={() => {
          navigate(-1)
        }}
      >
        返回
      </Button>
    </Card>
  )
}
